import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:get/state_manager.dart';
import 'package:get/get.dart';

class PravicyAlert extends StatefulWidget {
  const PravicyAlert({super.key});


static show(BuildContext context) {
    return showGeneralDialog(
                  context: context,
                  pageBuilder: (context, anim1, anim2) { return Container(); },
                  barrierColor: const Color(0x80000000),
                  barrierDismissible: true,
                  barrierLabel: '',
                  transitionDuration: const Duration(milliseconds: 200),
                  transitionBuilder: (context, anim1, anim2, child) {
                    return Transform.scale(
                      scale: anim1.value,
                      child: PravicyAlert(),
                    );
                  });
  }

  @override
  State<PravicyAlert> createState() => _PravicyAlertState();
}

class _PravicyAlertState extends State<PravicyAlert> {
 static const String pravicyText = '亲爱的客户，为了获得您的资格并加快您的贷款支付，我们需要访问您的如下权限\n\n相册\n您需要授权访问您的相册才能加载KYC文档和照片以完成该过程。\n\n设备信息\n您需要授权访问您的相册才能加载KYC文档和照片以完成该过程。\n\n应用程序\n应用程序需要访问您设备上的信息并能够采取措施。\n\n摄像机\n您需要授权访问您设备的摄像头才能完成该过程。';
  var selState = 1.obs;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.transparent,
      body: SafeArea(child: Container(
        height: 508,
        margin: const EdgeInsets.only(left: 16, right: 16, top: 76),
        decoration: const BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(16)), color: Colors.white),
        child: Container(
          // color: Colors.blue,
          padding: const EdgeInsets.only(left: 16, right: 16),
          child: Column(children: [
            const SizedBox(height: 14,),
            const Text('Pengungkapan izin', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Color(0xFF000000)),),
            const SizedBox(height: 14),
            const Text(pravicyText, style: TextStyle(fontSize: 14, fontWeight: FontWeight.w300, color: Color(0xFF000000)),),
            const SizedBox(height: 12),
            pravicyTextRow(),
            const SizedBox(height: 12),
            buttonsRow()
          ],),
        ),
      )),
    );
  }

Widget pravicyTextRow() {
  return Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                Obx(() => GestureDetector(
                  onTap: () => {
                    if (selState.value==0) { selState.value = 1 } else { selState.value = 0 }
                  },
                  child: Icon(Icons.check_circle, color: selState.value==1 ? const Color(0xFF2AC285):const Color(0x80000000), size: 18,))),
                const SizedBox(width: 8),
                privasiText,
                const SizedBox(width: 8)
              ],
            );
}

  Widget buttonsRow() {
    return Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                // const SizedBox(width: 22),
              SizedBox(
                height: 44,
                width: 120,
                child: OutlinedButton(
                onPressed: (){
                  Navigator.pop(context);
                }, 
                style: const ButtonStyle(side: MaterialStatePropertyAll(BorderSide(color: Color(0xFF1EB989), width: 1.5))),
                child: const Text('Menolak', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Color(0xFF1EB989)),)),
              ),
              const SizedBox(width: 40),
              SizedBox(
                height: 44,
                width: 120,
                child: Obx(() => ElevatedButton(
                onPressed: selState.value==1 ? (){}:null, 
                style: ButtonStyle(backgroundColor: MaterialStateProperty.all(selState.value==1 ?Color(0xFF1EB989):Colors.grey)),
                child: const  Text('Setuju', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color:Color(0xFFFFFFFF)))),)
              )
            ],);
  }


  Widget privasiText = Expanded(child: RichText(
    textAlign: TextAlign.left,
    text: TextSpan(
      text:
          'Baca pernyataan otorisasi dengan saksama dan klik "Lanjutkan" menunjukkan bahwa Anda menyetujui perjanjian privasi kami. ',
      style: const TextStyle(color: Color(0xFFACACAC), fontSize: 12),
      children: <TextSpan>[
        TextSpan(
          text: 'Privasi kami',
          style: const TextStyle(
              fontWeight: FontWeight.bold, color: Color(0xFF1EB989)),
          recognizer: TapGestureRecognizer()
            ..onTap = () {
              print('Privasi kami');
            },
        )
      ],
    ),
  ));
}